﻿
// 功能模块grid展示
Module_ArticleList = function (id) {
    

    var Module_ArticleStore = null;
    var url = "/manager/Module_Article/List/" + id;
    var oldUrl = url;
    var sm = Ext.create('Ext.selection.CheckboxModel');
    var searchWord = "";

    Ext.define('Tags' + id, {
        extend: 'Ext.data.Model',
        fields: [
        { type: 'string', name: 'Id' },
        { type: 'string', name: 'TagName' }

    ]
    });
  
    // Example of automatic remote store queries and use of various display templates
    var remoteStatesStore = Ext.create('Ext.data.Store', {
        model: 'Tags' + id,
        storeId: 'RemoteStates' + id,
        proxy: {
            type: 'ajax',
            actionMethods: 'post',
            url: '/manager/Normal_Tags/list2/',
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            }
        }
    });



    //grid 填充
    Ext.define('Module_ArticleGridModel' + id, {
        extend: 'Ext.data.Model',
        fields: [
            { name: "Id", type: "string" },
            { name: "ChannelId", type: "string" },
            { name: "Title", type: "string" },
            { name: "AddDate", type: "datetime" },
            { name: "IsPass", type: "string" },
            { name: "IsImg", type: "string" },
            { name: "UserId", type: "string" },
            { name: "Enabled", type: "string" }
            ]
    });



    //grid获取 json数组
    Module_ArticleStore = Ext.create('Ext.data.Store', {
        pageSize: CMN.pageSize,
        model: 'Module_ArticleGridModel' + id,
        // buffered: true,  //是否动态加载
        remoteSort: true, //加这个排序成功
        params: {
            group: 3,
            type: 'user'
        },
        proxy: {
            actionMethods: 'post',
            type: 'ajax',
            url: url,
            reader: {
                type: 'json',
                root: 'root',
                totalProperty: 'totalPorperty'
            },
            extraParams: {
                s: searchWord
            }
        },
        sorters: [{
            property: 'Id',
            direction: 'DESC'
        }]
    });

    //分页设置
    var pagingBar = Ext.create('Ext.PagingToolbar', {
        displayInfo: true, emptyMsg: "没有数据显示", displayMsg: "显示从{0}条数据到{1}条数据，共{2}条数据",
        store: Module_ArticleStore,
        pageSize: CMN.pageSize,
        //显示右下角信息
        prevText: "上一页",
        nextText: "下一页",
        refreshText: "刷新",
        lastText: "最后页",
        firstText: "第一页",
        beforePageText: "当前页",
        afterPageText: "共{0}页"
    });
    //删除选中行信息
    var DeleteModule_ArticleFn = function () {
        var row = Ext.getCmp("Module_ArticleGrid" + id).getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "请您至少选择一个!");
        }
        else if (row.length > 1) {
            var idList = "";
            for (var i = 0; i < row.length; i++) {
                if (i == 0) {
                    idList = row[0].data.Id;
                }
                else {
                    idList = idList + "_" + row[i].data.Id;
                }
            }
            //Ext.helper.msg("提示信息", "对不起只能选择一个!");
            Ext.Msg.confirm("提 示!", "您确定要删除" + idList + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Module_Article/DeleteList/" + idList,
                        method: "get",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Module_ArticleStore.loadPage(pagingBar.getPageData().currentPage);
                                Ext.helper.msg("恭喜", "删除成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("删除失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "删除失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                        }
                    })
                }
                else {

                }
            })
        }
        else if (row.length == 1) {
            Ext.Msg.confirm("提 示!", "您确定要删除" + row[0].data.Id + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Module_Article/Delete/" + row[0].data.Id,
                        method: "POST",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Module_ArticleStore.loadPage(pagingBar.getPageData().currentPage);
                                Ext.helper.msg("恭喜", "删除成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg("删除失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", "删除失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", "修改失败!");
                        }
                    })
                }
                else {

                }
            })
        }
    }


    //修改选中行信息
    var EditModule_ArticleFn = function () {
        //Ext.MessageBox.hide();
        var row = Ext.getCmp("Module_ArticleGrid" + id).getSelectionModel().getSelection();
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "您没有选中任何行!");
        }
        else if (row.length > 1) {
            Ext.helper.msg("提示信息", "对不起只能选择一个!");
        } else if (row.length == 1) {
            EditModule_Article(row[0].data.Id);
            //console.log(EditModule_Article);
            //alert("EditModule_Article" + id);
            //alert(Ext.getCmp("EditModule_Article" + id));

        }

    }

    //新增信息
    var SaveModule_ArticleFn = function () {
        InsertModule_Article();
    }



    var UpdateList = function (item) {
        var row = Ext.getCmp("Module_ArticleGrid" + id).getSelectionModel().getSelection();
        var tip = item.text;
        if (row.length == 0) {
            Ext.helper.msg("提示信息", "请您至少选择一个!");
        }
        else {
            var idList = "";
            for (var i = 0; i < row.length; i++) {
                if (i == 0) {
                    idList = row[0].data.Id;
                }
                else {
                    idList = idList + "_" + row[i].data.Id;
                }
            }
            //Ext.helper.msg("提示信息", "对不起只能选择一个!");
            Ext.Msg.confirm("提 示!", "您确定要" + tip + idList + "吗?", function (btn) {
                if (btn == "yes") {
                    Ext.Ajax.request({
                        url: "/manager/Module_Article/UpdateList/" + item.value + "?id=" + idList,
                        method: "get",
                        success: function (d) {
                            //成功后
                            var action = Ext.JSON.decode(d.responseText);
                            //alert(action.success);
                            var flag = action.success;
                            if (flag == "true") {
                                Module_ArticleStore.loadPage(1);
                                Ext.helper.msg("恭喜", tip + "成功!");
                            }
                            else {
                                var message = action.result.message;
                                if (message) {
                                    Ext.helper.msg(tip + "失败!", message);
                                }
                                else {
                                    Ext.helper.msg("提示!", tip + "失败!");
                                }
                            }
                        },
                        failure: function (form, action) {
                            Ext.MessageBox.alert("提示!", tip + "失败!");
                        }
                    })
                }
                else {

                }
            })
        }

    }
    var SearchList = function () {

        searchWord = Ext.getCmp("searchTxt" + id).getValue();
        Module_ArticleStore.proxy.extraParams.s = searchWord;
        Module_ArticleStore.loadPage(1);

    }
    var gridTbar = Ext.create('Ext.toolbar.Toolbar', {
        items: [
        {
            xtype: 'splitbutton',
            text: '批量操作',
            iconCls: 'add16',
            menu: [{
                text: "审核",
                tooltip: "审核",
                value: "check",
                iconCls: "addicon",
                handler: UpdateList
            }, {
                text: "取消审核",
                tooltip: "取消审核",
                value: "uncheck",
                iconCls: "editicon",
                handler: UpdateList
            }, {
                text: "移入回收站",
                tooltip: "取消审核",
                value: "inrecycle",
                iconCls: "deleteicon",
                handler: UpdateList
            }, {
                text: "移出回收站",
                tooltip: "取消审核",
                value: "outrecycle",
                iconCls: "deleteicon",
                handler: UpdateList
            }, {
                text: "删除",
                tooltip: "删除",
                iconCls: "deleteicon",
                handler: DeleteModule_ArticleFn
            }, {
                text: "启用",
                tooltip: "启用",
                iconCls: "editicon",
                value: "enabled",
                handler: UpdateList
            }, {
                text: "设为未启用",
                tooltip: "设为未启用",
                value: "disenabled",
                iconCls: "deleteicon",
                handler: UpdateList
            }]
        }, {
            text: "新增",
            tooltip: "新增",
            iconCls: "addicon",
            handler: SaveModule_ArticleFn
        }, "", "-", "", {
            text: "编辑",
            tooltip: "编辑",
            iconCls: "editicon",
            handler: EditModule_ArticleFn
        }, "", "-", "", {
            text: "删除",
            tooltip: "删除",
            iconCls: "deleteicon",
            handler: DeleteModule_ArticleFn
        }, "-"
        , {
            xtype: 'textfield',
            name: 'searchTxt' + id,
            id: 'searchTxt' + id,
            emptyText: '输入搜索关键词'
        }, "", {
            text: "搜索",
            tooltip: "搜索",
            handler: SearchList
        }]
    });

    //grid配置
    var grid = Ext.create('Ext.grid.Panel', {
        id: "Module_ArticleGrid" + id,
        renderTo: "Module_ArticleGrid" + id,
        layout: "fit",
        alias: 'widget.methodPanel',
        columnLines: true,
        loadMask: true,
        frame: true,
        border: false,
        selModel: sm,   //选择框
        autoScroll: true,
        store: Module_ArticleStore,
        ds: Module_ArticleStore,
        sm: sm,
        columnLines: true,
        //cm: cm2,
        viewConfig: {
            stripeRows: true,
            trackOver: true,
             enableTextSelection: true,
            emptyText: '<div style="color:#999;margin:5px;">当前没有记录显示<div>'
        },
        stripeRows: true,
        listeners: {
            "itemdblclick": function (g, rowIndex, e) {
                EditModule_ArticleFn();
            }
        },
        bbar: pagingBar,
        tbar: gridTbar,
        columns: [
               Ext.create('Ext.grid.RowNumberer'),
                { header: "文章ID", dataIndex: "Id", width: 80, sortable: true },
                { header: "频道ID", dataIndex: "ChannelId", width: 80, sortable: true },
                { header: "文章标题", dataIndex: "Title", width: 200, sortable: true },
                { header: "添加时间", dataIndex: "AddDate", width: 80, sortable: true },
                { header: "状态", dataIndex: "IsPass", width: 60, renderer: function (value) { if (value == 1) { return "审核"; } else if (value == 2) { return "回收站中"; } else { return "未审"; } }, sortable: true },
                { header: "推荐图片", dataIndex: "IsImg", width: 60, renderer: function (value) { if (value == "true") { return "是"; } else { return "否"; } }, sortable: true },
                { header: "添加用户", dataIndex: "UserId", width: 60, sortable: true },
                { header: "是否启用", dataIndex: "Enabled", width: 60, renderer: function (value) { if (value == "true") { return "是"; } else { return "否"; } }, sortable: true }
        //{ header: "删除", width: 40, dataIndex: "Id", renderer: function (value) { return "<a href='javascript:DeleteModule_ArticleFn();' title='删除'  class='deleteBtn' >&nbsp;&nbsp;&nbsp;</a>" } }
            ]
    });





    var ShowNormal_UploadImageWin = function (edit) {
        Normal_UploadImageWin = new Ext.Window({
            title: '添加图片',
            width: 900,
            height: document.body.clientHeight - 40,
            layout: "fit",
            resizable: false,
            defaultType: "textfield",
            collapsible: true, //允许缩放条
            closeAction: 'destroy',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            loader: {
                url: '/Manager/Normal_UploadImage/Index/' + id + "_" + edit,
                contentType: 'html',
                autoLoad: true,
                scripts: true,
                scope: this,
                loadMask: true
            }
        });

        Normal_UploadImageWin.show();
    }



    //新增文章
    var InsertModule_Article = function () {
        var InsertModule_ArticleForm = Ext.create("Ext.form.Panel", {
            width: 900,
            height: document.body.clientHeight - 130,
            id: "InsertModule_Article" + id,
            autoScroll: true,
            layout: "anchor",
            defaultType: "textfield",
            labelWidth: 55,
            baseCls: "x-plain",
            defaults: { labelAlign: 'right', msgTarget: "side" },
            buttonAlign: "center",
            bodyStyle: "padding:0 0 0 0",
            items: [{
                name: "Title",
                fieldLabel: "<font color='red'>*</font>文章标题",
                allowBlank: false,
                blankText: "文章标题不能为空"
            }, {
                xtype: 'checkboxgroup',
                fieldLabel: '扩展属性',
                name: "Flag",
                columns: 10,
                items: sys_FieldValueFlags
            }, {
                name: "TColor",
                fieldLabel: "标题颜色"
            }, {
                name: "Summary",
                xtype: 'textareafield',
                fieldLabel: "摘要",
                width: 400,
                blankText: "摘要不能为空"
            }, {
                name: "Editor",
                fieldLabel: "编辑",
                blankText: "编辑不能为空"
            }, {
                name: "Author",
                fieldLabel: "作者"
            }, {

                xtype: "datefield",
                name: "AddDate",
                fieldLabel: "<font color='red'>*</font>添加时间",
                allowBlank: false,
                value: new Date(),
                format: 'Y-m-d H:i:s',
                blankText: "添加时间不能为空"
            }, {

                name: "IsImg",
                fieldLabel: "推荐图片",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: false,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                xtype: 'fieldcontainer',
                fieldLabel: '缩略图',
                layout: 'vbox',
                width: 500,
                defaults: { labelAlign: 'right', msgTarget: "side" },
                items: [{
                    name: "Img",
                    xtype: "textfield",
                    width: 460,
                    blankText: "图片地址不能为空"
                }, {
                    xtype: 'button',
                    text: '上传缩略图',
                    handler: function () {
                        ShowNormal_UploadImageWin("Insert");
                    }
                }]

            }, {

                name: "SourceFrom",
                fieldLabel: "来源"
            }, {
             xtype:'checkbox',
                checked: true,
                fieldLabel: '扩展',
                boxLabel: '自动提取缩略图',
                name: 'IsAutoImg',
                inputValue: '1'
            }, 
             new Ext.create("Ext.ux.ueditor", {
                name: "TextContent",
                labelAlign: 'right',
               
               
                allowBlank: false,
                fieldLabel: "<font color='red'>*</font>文章内容",
                width:800,
                height:600
            }), {
                xtype: 'fieldcontainer',
                fieldLabel: '标签',
                layout: 'vbox',
                width: 500,
                
                defaults: { labelAlign: 'right', msgTarget: "side" },
                items: [
                    Ext.create('Ext.ux.form.field.BoxSelect', {
                        // Remote store things
                        store: 'RemoteStates' + id,
                        width: 260,
                        name: "Tags",
                        pageSize: 10,
                        displayField: 'TagName',
                        valueField: 'Id',
                        queryMode: 'remote',
                        allowBlank: true,
                        // Value delimiter examples
                        delimiter: ',',
                        minChars: 2,
                        // Click behavior
                        triggerOnClick: false,

                        // Display template modifications
                        labelTpl: '{TagName} ({Id})',
                        listConfig: {
                            tpl: [
                    '<ul><tpl for=".">',
                    '<li role="option" class="' + Ext.baseCSSPrefix + 'boundlist-item' + '">{TagName}</li>',
                    '</tpl></ul>'
                    ]
                        }
                    }), {
                        xtype: 'button',
                        text: '新增Tag',
                        handler: function () {
                            InsertNormal_Tags(InsertModule_ArticleForm, remoteStatesStore);
                        }
                    }
                ]
            }, {
                name: "OrderNum",
                fieldLabel: "<font color='red'>*</font>排序数",
                allowBlank: false,
                value: 0,
                blankText: "排序数不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                xtype: 'radiogroup',
                fieldLabel: '居顶时间',
                name: "toptime",
                columns: 10,
                items: sys_FieldValueTopNum
            }, {
                name: "ViewNum",
                fieldLabel: "浏览次数",
                blankText: "浏览次数不能为空",
                value: 0,
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "SupportNum",
                fieldLabel: "支持数",
                blankText: "支持数不能为空",
                value: 0,
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "AgainstNum",
                fieldLabel: "反对数量",
                blankText: "反对数量不能为空",
                value: 0,
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "IsPass",
                fieldLabel: "是否审核",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: 1,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "审核", "value": 1 },
                    { "show": "回收站中", "value": 2 },
			        { "show": "未审", "value": 0 }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                name: "Enabled",
                fieldLabel: "是否启用",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: true,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                name: "ReadGroup",
                fieldLabel: "读取文章权限",
                blankText: "读取文章权限不能为空",
                regex: /^[\d]{0,10}$/,
                hidden: true,
                value: 0,
                regexText: "请填写0～10个数字"
            }, {
                name: "WriteComment",
                fieldLabel: "评论权限",
                blankText: "评论权限不能为空",
                regex: /^[\d]{0,10}$/,
                hidden: true,
                value: 0,
                regexText: "请填写0～10个数字"
            }, {
                name: "ReadComment",
                fieldLabel: "查看评论权限",
                hidden: true,
                value: 0,
                blankText: "查看评论权限不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {

                name: "Remark",
                fieldLabel: "备注",
                xtype: 'textareafield'
            }
			]
        });


        var InsertModule_ArticleWin = Ext.create('Ext.window.Window', {
            title: "新增文章",
            width: 940,
            height: document.body.clientHeight - 50,
            collapsible: true, //允许缩放条
            closeAction: 'destroy',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            items: [InsertModule_ArticleForm],

            buttons: [{
                text: "保存信息",
                minWidth: 70,
                handler: function () {
                    if (InsertModule_ArticleForm.getForm().isValid()) {
                        //弹出效果 Ext.MessageBox.alert("asdf");
                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function () { }, 1000);
                        InsertModule_ArticleForm.form.submit({
                            url: "/manager/Module_Article/Insert/" + id,
                            method: "POST",
                            success: function (form, action) {
                                //成功后
                                Ext.MessageBox.hide();
                                var flag = action.result.success;
                                if (flag == "true") {
                                    Ext.MessageBox.hide();
                                    Module_ArticleStore.loadPage(1);
                                    Ext.helper.msg("恭喜", "新增成功!");
                                    InsertModule_ArticleWin.destroy();
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("新增失败!", message);
                                    }
                                    else {
                                        Ext.helper.msg("提示!", "新增失败!");
                                        InsertModule_ArticleWin.destroy();
                                    }

                                }
                            },
                            failure: function (form, action) {
                                Ext.MessageBox.alert("提示!", "新增失败!");
                            }
                        });
                    }
                }
            }, {
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function () {
                    //加载表单数据
                    InsertModule_ArticleForm.getForm().reset();
                }
            }, {
                text: "取 消",
                minWidth: 70,
                handler: function () {
                    InsertModule_ArticleWin.destroy();
                }
            }]

        });

        InsertModule_ArticleWin.show();
    }




    //编辑文章
    var EditModule_Article = function (eId) {
        // Example of automatic remote store queries and use of various display templates
        var EditremoteStatesStore = Ext.create('Ext.data.Store', {
            model: 'Tags' + id,
            storeId: 'EditRemoteStates' + id,
            proxy: {
                type: 'ajax',
                actionMethods: 'post',
                url: '/manager/Module_Article/tagList/' + eId,
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalPorperty'
                }
            }
        });
        var EditModule_ArticleForm = Ext.create("Ext.form.Panel", {
            width: 900,
            id: "EditModule_Article" + id,
            height: document.body.clientHeight - 130,
            autoScroll: true,
            layout: "anchor",
            defaultType: "textfield",
            labelWidth: 55,
            baseCls: "x-plain",
            defaults: { labelAlign: 'right', msgTarget: "side" },
            buttonAlign: "center",
            bodyStyle: "padding:0 0 0 0",
            items: [{
                name: "Id",
                fieldLabel: "<font color='red'>*</font>文章ID",
                allowBlank: false,
                hidden: true,
                blankText: "文章ID不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "ChannelId",
                fieldLabel: "<font color='red'>*</font>频道ID",
                allowBlank: false,
                blankText: "频道ID不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "Path",
                fieldLabel: "<font color='red'>*</font>栏目路径",
                allowBlank: false,
                blankText: "栏目ID不能为空",
                regex: /^[\da-zA-Z]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "Title",
                fieldLabel: "<font color='red'>*</font>文章标题",
                allowBlank: false,
                blankText: "文章标题不能为空"
            }, {
                xtype: 'checkboxgroup',
                fieldLabel: '扩展属性',
                name: "Flag",
                columns: 10,
                items: sys_FieldValueFlags
            }, {
                name: "TColor",
                fieldLabel: "标题颜色"
            }, {
                name: "Summary",
                xtype: 'textareafield',
                fieldLabel: "摘要",
                width: 400,
                blankText: "摘要不能为空"
            }, {
                name: "Editor",
                fieldLabel: "编辑",
                blankText: "编辑不能为空"
            }, {
                name: "Author",
                fieldLabel: "作者"
            }, {

                xtype: "datefield",
                name: "AddDate",
                fieldLabel: "<font color='red'>*</font>添加时间",
                allowBlank: false,
                value: new Date(),
                format: 'Y-m-d H:i:s',
                blankText: "添加时间不能为空"
            }, {

                name: "IsImg",
                fieldLabel: "推荐图片",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: false,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                xtype: 'fieldcontainer',
                fieldLabel: '缩略图',
                layout: 'vbox',
                width: 500,
                defaults: { labelAlign: 'right', msgTarget: "side" },
                items: [{
                    name: "Img",
                    xtype: "textfield",
                    width: 460,
                    blankText: "图片地址不能为空"
                }, {
                    xtype: 'button',
                    text: '上传缩略图',
                    handler: function () {
                        ShowNormal_UploadImageWin("Edit");
                    }
                }]

            }, {

                name: "SourceFrom",
                fieldLabel: "来源"
            }, {
                xtype: 'checkbox',
                checked: true,
                fieldLabel: '扩展',
                boxLabel: '自动提取缩略图',
                name: 'IsAutoImg',
                inputValue: '1'
            }, 
             new Ext.create("Ext.ux.ueditor", {
                name: "TextContent",
                labelAlign: 'right',
                UConfig: { minFrameHeight: 600 },
                allowBlank: false,
                fieldLabel: "<font color='red'>*</font>文章内容",
                width: 800,
                height: 600
            }), {
                xtype: 'fieldcontainer',
                fieldLabel: '标签',
                width: 500,
                defaults: { labelAlign: 'right', msgTarget: "side" },
                items: [
                    Ext.create('Ext.ux.form.field.BoxSelect', {
                        // Remote store things
                        store: 'EditRemoteStates' + id,
                        width: 260,
                        name: "Tags",
                        pageSize: 10,
                        value: "2,3",
                        displayField: 'TagName',
                        valueField: 'Id',
                        queryMode: 'remote',
                        allowBlank: true,
                        // Value delimiter examples
                        delimiter: ',',
                        minChars: 2,
                        // Click behavior
                        triggerOnClick: false,

                        // Display template modifications
                        labelTpl: '{TagName} ({Id})',
                        listConfig: {
                            tpl: [
                    '<ul><tpl for=".">',
                    '<li role="option" class="' + Ext.baseCSSPrefix + 'boundlist-item' + '">{TagName}</li>',
                    '</tpl></ul>'
                    ]
                        }
                    }), {
                        xtype: 'button',
                        text: '新增Tag',
                        handler: function () {
                            InsertNormal_Tags(EditModule_ArticleForm, EditremoteStatesStore);
                        }
                    }
                ]
            }, {
                name: "UserId",
                fieldLabel: "<font color='red'>*</font>添加用户ID",
                allowBlank: false,
                blankText: "添加用户ID不能为空"
            }, {
                xtype: 'radiogroup',
                fieldLabel: '居顶时间',
                name: "toptime",
                columns: 10,
                items: sys_FieldValueTopNum
            }, {

                name: "OrderNum",
                fieldLabel: "<font color='red'>*</font>排序数",
                allowBlank: false,
                value: 0,
                blankText: "排序数不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "IsPass",
                fieldLabel: "是否审核",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: 1,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "审核", "value": 1 },
                    { "show": "回收站中", "value": 2 },
			        { "show": "未审", "value": 0 }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                name: "Enabled",
                fieldLabel: "是否启用",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: true,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
          
            }, {
                name: "IsCreateIndex",
                fieldLabel: "是否重新索引",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                value: false,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": true },
			        { "show": "否", "value": false }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'
            }, {
                name: "ViewNum",
                fieldLabel: "浏览次数",
                blankText: "浏览次数不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "SupportNum",
                fieldLabel: "支持数",
                blankText: "支持数不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "AgainstNum",
                fieldLabel: "反对数量",
                blankText: "反对数量不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "ReadGroup",
                fieldLabel: "读取文章权限",
                blankText: "读取文章权限不能为空",
                regex: /^[\d]{0,10}$/,
                hidden: true,
                value: 0,
                regexText: "请填写0～10个数字"
            }, {
                name: "WriteComment",
                hidden: true,
                value: 0,
                fieldLabel: "评论权限",
                blankText: "评论权限不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {
                name: "ReadComment",
                fieldLabel: "查看评论权限",
                hidden: true,
                value: 0,
                blankText: "查看评论权限不能为空",
                regex: /^[\d]{0,10}$/,
                regexText: "请填写0～10个数字"
            }, {

                name: "Remark",
                fieldLabel: "备注",
                xtype: 'textareafield'
            }
			]
        });
        var EditModule_ArticleWin = new Ext.Window({
            title: "修改文章",
            width: 940,
            height: document.body.clientHeight - 50,

            layout: "fit",
            //iconCls: "addicon",
            //不可以随意改变大小
            resizable: false,
            //是否可以拖动
            //draggable:false,
            defaultType: "textfield",
            //labelWidth: 100,
            collapsible: true, //允许缩放条
            closeAction: 'destroy',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            items: [EditModule_ArticleForm],
            listeners: {
                "show": function () {
                    if (id && id != "") {
                        //加载表单数据
                        EditModule_ArticleForm.form.load(
                                {
                                    url: "/manager/Module_Article/Look/" + eId,
                                    method: "get",
                                    success: function (form, action) {
                                       // console.log(form);
                                        var mydata = action.result.data;
                                        var flag = Ext.decode("{checkboxgrupflag:[\"" + mydata.Flag + "\"]}");
                                        form.findField("Flag").setValue(flag);
                                        //form.findField("Tags").setValue(mydata.Tags);
                                        //console.log(flag);
                                    },
                                    failure: function (form, action) {
                                        Ext.Msg.alert("提示信息", "对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                    }
                }
            },
            buttons: [{
                text: "保存信息",
                minWidth: 70,
                handler: function () {
                    //alert(EditModule_ArticleForm.getForm().isValid())
                    if (EditModule_ArticleForm.getForm().isValid()) {
                        //弹出效果 Ext.MessageBox.alert("asdf");
                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function () { }, 1000);
                        EditModule_ArticleForm.form.submit({
                            url: "/manager/Module_Article/Update/" + eId,
                            method: "POST",
                            success: function (form, action) {
                                //成功后
                                Ext.MessageBox.hide();
                                var flag = action.result.success;
                                if (flag == "true") {
                                    Module_ArticleStore.loadPage(pagingBar.getPageData().currentPage);
                                    Ext.helper.msg("恭喜", "修改成功!");
                                    EditModule_ArticleWin.destroy();
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("修改失败!", message);
                                    }
                                    else {
                                        Ext.helper.msg("提示!", "修改失败!");
                                       
                                    }

                                }
                            },
                            failure: function (form, action) {
                                Ext.MessageBox.alert("提示!", "修改失败!");
                                
                            }
                        });
                    }
                }
            }, {
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function () {
                    //加载表单数据
                    EditModule_ArticleForm.getForm().reset();
                    EditModule_ArticleForm.form.load(
                                {
                                    url: "/manager/Module_Article/Look/" + eId,
                                    method: "get",
                                    success: function (form, action) {
                                    },
                                    failure: function (form, action) {
                                        //Ext.helper.msg("提示信息","对不起加载数据失败!请联系管理员");
                                    }
                                }
                    );
                }
            }, {
                text: "取 消",
                minWidth: 70,
                handler: function () {
                    EditModule_ArticleWin.destroy();
                }

            }]

        });

        EditModule_ArticleWin.show();
    }
    Module_ArticleStore.loadPage(1);

    //新增标签
    var InsertNormal_Tags = function (addForm, StatesStore) {
      
        var channelsTree = Ext.create("Ext.ux.comboboxtree", {
            name: 'ChannelPath',
            storeUrl: '/Manager/Module_Manager/List2/',
            fieldLabel: "所属栏目",
            labelAlign: 'right',
            treeNodeParameter: 'text',
            displayField: 'text',
            queryMode: 'local',
            valueField: 'id'
        });
        Ext.define("TagsChannel", {
            extend: 'Ext.data.Model',
            proxy: {
                actionMethods: 'post',
                type: 'ajax',
                url: '/Manager/Module_Manager/List2/',
                reader: {
                    type: 'json',
                    root: 'root',
                    totalProperty: 'totalPorperty'
                }
            },

            fields: ['Id', 'Title', 'Path']
        });

        //模板
        var channelStore = Ext.create('Ext.data.Store', {
            // autoLoad: true,
            pageSize: 1000,
            model: 'TagsChannel'
        });
        var InsertNormal_TagsForm = Ext.create("Ext.form.Panel", {
            width: 360,
            height: 450,
            plain: true,
            autoScroll: true,
            layout: "anchor",
            defaultType: "textfield",
            labelWidth: 55,
            baseCls: "x-plain",
            defaults: { labelAlign: 'right', anchor: '90%', msgTarget: "side" },
            buttonAlign: "center",
            bodyStyle: "padding:0 0 0 0",
            items: [{
                name: "TagName",
                fieldLabel: "<font color='red'>*</font>标签名称",
                allowBlank: false,
                blankText: "标签名称不能为空",
                regex: /^[\s\S]{1,12}$/,
                regexText: "请填写1～50个数字或字母"
            }, {
                name: "ChannelPath",
                fieldLabel: "所属栏目",
                xtype: "combo",
                //传入后台真实值value field /value
                anchor: '90%',
                store: channelStore,
                autoRender: false,
                displayField: 'Title',
                queryMode: 'Path',
                valueField: 'Path'
            }, {
                name: "IsRecommend",
                fieldLabel: "是否推荐",
                xtype: "combo",
                //传入后台真实值value field /value
                editable: false,
                anchor: '90%',
                value: 0,
                store: Ext.create('Ext.data.Store', {
                    fields: ['show', 'value'],
                    data: [
			        { "show": "是", "value": 1 },
			        { "show": "否", "value": 0 }
			    ]
                }),
                queryMode: 'local',
                displayField: 'show',
                valueField: 'value'

            }, {
                name: "OrderNum",
                fieldLabel: "排序",
                regex: /^[\d]{1,10}$/,
                value: 100,
                regexText: "请填写1～10个数字"
            }
			]
        });


        var InsertNormal_TagsWin = Ext.create('Ext.window.Window', {
            title: "新增标签",
            width: 400,
            height: 450,
            plain: true,
            layout: "fit",
            //不可以随意改变大小
            resizable: false,
            //是否可以拖动
            //draggable:false,
            defaultType: "textfield",
            collapsible: true, //允许缩放条
            closeAction: 'hide',
            closable: true,
            //弹出模态窗体
            modal: 'true',
            buttonAlign: "center",
            bodyStyle: "padding:10px 0 0 15px",
            items: [InsertNormal_TagsForm],

            buttons: [{
                text: "保存信息",
                minWidth: 70,
                handler: function () {
                    //alert(InsertNormal_TagsForm.getForm().isValid())
                    if (InsertNormal_TagsForm.getForm().isValid()) {
                        //弹出效果 Ext.MessageBox.alert("asdf");

                        Ext.MessageBox.show
                                (
                                    {
                                        msg: '正在保存，请稍等...',
                                        progressText: 'Saving...',
                                        width: 300,
                                        wait: true,
                                        waitConfig: { interval: 200 },
                                        icon: 'download',
                                        animEl: 'saving'
                                    }
                                );
                        setTimeout(function () { }, 1000);
                        InsertNormal_TagsForm.form.submit({
                            url: "/manager/Normal_Tags/Insert/",
                            method: "POST",
                            success: function (form, action) {
                                //成功后
                                Ext.MessageBox.hide();
                                var flag = action.result.success;
                                if (flag == "true") {
                                    var tagName = InsertNormal_TagsForm.getForm().findField("TagName").getValue();
                                    var tagId = action.result.message;
                                    StatesStore.add({ Id: "" + tagId, TagName: tagName });
                                    var oldTagValue = addForm.getForm().findField("Tags").getValue();
                                    if (oldTagValue != "")
                                        oldTagValue = oldTagValue + ",";
                                    addForm.getForm().findField("Tags").setValue(oldTagValue + tagId);
                                    Ext.helper.msg("恭喜", "新增成功!");
                                    InsertNormal_TagsWin.hide();
                                }
                                else {
                                    var message = action.result.message;
                                    if (message) {
                                        Ext.MessageBox.alert("新增失败!", message);
                                    }
                                    else {
                                        Ext.MessageBox.alert("提示!", "新增失败!");
                                        InsertNormal_TagsWin.hide();
                                    }

                                }
                            },
                            failure: function (form, action) {
                                Ext.MessageBox.alert("提示!", "新增失败!");
                            }
                        });
                    }
                }
            }, {
                text: "重置",
                minWidth: 70,
                qtip: "重置数据",
                handler: function () {
                    //加载表单数据
                    InsertNormal_TagsForm.getForm().reset();
                }
            }, {
                text: "取 消",
                minWidth: 70,
                handler: function () {
                    InsertNormal_TagsWin.hide();
                }
            }]

        });
        InsertNormal_TagsWin.show();
    }


   

}



